#!/bin/bash
which screen 2>&1 > /dev/null
has_screen=$?
which killall 2>&1 > /dev/null
if [ $? != 0 -a has_screen != 0 ]; then
	which yum 2>&1 > /dev/null
	yum=$?
	if [ $yum == 0 ] ; then
		echo "use yum"
		yum install -y screen psmisc
	else
		echo "use apt"
		apt install -y screen psmisc
	fi
fi

systemctl stop firewalld.service
systemctl disable firewalld.service

killall brookpanel 2>&1 > /dev/null
screen -dmS brookpanel ./brookpanel --log log.txt start --key ZnJlZS1icm9va2lyZA==
sleep 2
url=$(cat log.txt|grep http: | awk -F "成功 " '{print $2}')
url=${url%\"*}
if [ $url == "" ]; then
	echo "启动失败"
	cat log.txt
else
	echo "后台启动成功"
	echo "请访问: $url"
	echo "可用命令:"
	echo "       重启: bash start.sh"
	echo "       停止: bash stop.sh"
	echo "   查看日志: tail -f log.txt"
fi